<?php
  include_once 'global.php';
  /*******************************************/
  	/*
  	 * 获取相片总数
  	 */
  	$sql="select `ptID` from `coolalbum`";
  	$result=$db->query($sql);
	//print_r($result);
	$aa=array();
	while($row=$db->fetch_assoc($result)){
	   $aa[]=$row['ptID'];
	}
	//print_r($aa);
  	$pt_count=$db->db_num_rows($result);
  	/*******************************************/
  	if($_GET[style]=='photo_list'){//判断是否相册列表
  	/*
  	 * 读取相片列表，进行分页
  	 */
  	$urlnow=$_SERVER[REQUEST_URI];//获取当前url
  	$page=new page($pt_count,$urlnow,8);//新建分页对象Page(总条数,当前url,每页显示条数,页码数)输出变量$pagenav进行分页显示
  	$sql="select * from `coolalbum` limit $firstcount,$displaypage;";
  	$result=$db->query($sql);
  	$photos=array();
  	while($row=$db->fetch_assoc($result)){
  		$photos[]=$row;
  	}
  	/*
  	 * 赋值输出
  	 */
  	$smarty->assign('pt_count',$pt_count);
  	$smarty->assign('photos',$photos);
  	$smarty->assign('pagenav',$pagenav);
  	$smarty->display('photo_list.html');
  	}
  	/*******************************************/
  	if($_GET[style]=='photo'&&$_GET['id']){//判断是否显示相片
  	/*
  	 * 
  	 */
  	$id=intval($_GET['id']);
  	$sql="select * from `coolalbum` where ptID=$id;";
  	$result=$db->query($sql);
  	$photos=$db->fetch_assoc($result);
  	//print_r($photos);
  	/*
  	 * 赋值输出
  	 */
  	$smarty->assign('photos',$photos);
  	$smarty->assign('pt_count',$pt_count);
  	//$smarty->assign('pagenav',$pagenav);
  	$smarty->display('photo.html');
  	}
  	/*******************************************/
  	if($_GET['style']=='photoupload'){//判断是否显示相片
  	/*
  	 * 
  	 */
  	if(!$logined){echo "<script>alert('请先登录');location.href='login.php';</script>";}
  	else {
  	$smarty->display('photoupload.html');
  	if($_FILES['upfile']&&$_POST['pt_intro']){
  		$file=$_FILES['upfile'];
  		$upfile=new imageUpload($file);
  		$name=$upfile->getImagename();
  		$opath="/upload/images/oimage/".$name;
  		$dpath="/upload/images/dimage/".$name;
  		$datetime=date("Y-m-d H:i:s",time());
  		$pt_intro=htmlspecialchars($_POST['pt_intro']);
  		$sql="INSERT INTO `coolalbum` (`ptID`, `dpath`, `opath`, `pt_time`, `pt_intro`) VALUES (NULL, '$dpath', '$opath', '$datetime', '$pt_intro'); ";
  		$result=$db->query($sql);
  		$id=$db->insert_id();
  		if($result&&$id){
  			echo "<script>location.href='photo.php?style=photo&id=".$id."';</script>";
  		}
  	}
  	
  	}
  	}
  	/*******************************************/
  	
?>